package com.xbongbong.saas.help;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.pro.domain.entity.ChartEntity;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.pro.statistic.enums.ChartTypeEnum;
import com.xbongbong.pro.statistic.model.ChartModel;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.sys.model.DepartmentModel;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/3/20 12:38
 * @since v1.0
 */
@Component
public class PkSetHelp {


    /**
     * 获取当前登陆人pk榜的交集员工
     * 1.登陆人的图表权限与单图表的可见权限交集
     * 2.登陆人与pk榜设置可见范围权限匹配
     * 3.登陆人，参与人与不参与人在不同的数据权限内交集员工
     */
    public List<String> pkRuleUserListCanSee(BaseDTO baseDTO, ChartEntity chartEntity){
        List<String> userList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        UserVO loginUser = baseDTO.getLoginUser();
        String corpid = baseDTO.getCorpid();

        // 角色权限是否有图表查看权限
        if (!loginUser.getPermSet().contains(ProPermissionAliasEnum.CHART_VIEW.getAlias())) {
            return userList;
        }
        // 非pk的图表，或者未开启，或者权限设置为空
        if(Objects.equals(chartEntity.getEnable(), BasicConstant.ZERO) || !Objects.equals(chartEntity.getChartType(), ChartTypeEnum.PK.getCode()) || chartEntity.getPermissions() == null){
            return userList;
        }



        return userList;

    }
}
